import { createRouter, createWebHistory } from 'vue-router'
import { dynamicRoutes } from './routes'
const router = createRouter({
    history: createWebHistory(import.meta.env.VITE_BASE_PATH),
    routes: [...dynamicRoutes],
})

/**
 * 重置路由保留静态路由
 */
export const resetRouter = (): void => {
    const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root']
    router.getRoutes().forEach((route) => {
        const { name } = route
        if (name && !resetWhiteNameList.includes(name as string)) {
            router.hasRoute(name) && router.removeRoute(name)
        }
    })
}

export default router
